package com.caijb.juc;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author caijb
 * @version 1.0
 * @data 2025/10/30 22:29
 */
public class ReentrantLockDemo {

    static ReentrantLock reentrantLock = new ReentrantLock();

    public static void main(String[] args) {
        new Thread(ReentrantLockDemo::test, "t1").start();
        new Thread(ReentrantLockDemo::test, "t2").start();
//        new Thread(ReentrantLockDemo::test, "t3").start();
//        new Thread(ReentrantLockDemo::test, "t4").start();
//        new Thread(ReentrantLockDemo::test, "t5").start();
//        new Thread(ReentrantLockDemo::test, "t6").start();
//        new Thread(ReentrantLockDemo::test, "t7").start();
    }

    private static void test() {
        reentrantLock.lock();
        try {
            System.out.println("线程" + Thread.currentThread().getName() + "进入");
        } finally {
            reentrantLock.unlock();
        }
    }
}
